<template>
	<view class="baseForm">
		<!--  <view class="code">
      <view class="codeTitle">耗材编号</view>
      <view>{{ formData?.id }}</view>
    </view> -->

		<view>
			<u--form
				labelPosition="top"
				:model="formData"
				:rules="rules"
				labelWidth="300"
				ref="uForm"
				class="form"
				errorType="toast">
				<u-loading-icon
					class="flex justify-center mt-20"
					textSize="18"
					v-show="loading"></u-loading-icon>

				<!-- 拆卸状态选择 -->
				<view
					class="plan card record-remarks"
					style="margin-bottom: 60px">
					<!-- 耗材编码 -->
					<u-form-item label="设备编码:" prop="remarks">
						<u-input
							:disabled="formData.equipCode != ''"
							v-model="formData.equipCode"
							placeholder="请输入设备编码"
							disabled
							height="45px"></u-input>
					</u-form-item>
					<u-form-item label="判定结果" prop="status" required>
						<u-radio-group v-model="formData.status">
							<u-radio
								:customStyle="{
									marginRight: '30px',
									fontSize: '14px',
								}"
								shape="square"
								v-for="(
									item, index
								) in useDictionaryStore().filterDictList(
									'cmsDisassembly'
								)"
								:key="index"
								:label="item.label"
								:name="item.value"></u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="判定描述" prop="remarks">
						<u--textarea
							v-model="formData.remarks"
							placeholder="请输入备注"
							height="45px"></u--textarea>
					</u-form-item>
				</view>

				<!-- 提交 -->
				<view class="submit_btn_div">
					<button type="default" class="grey_btn" @click="resetData">
						重 置
					</button>
					<button
						type="primary"
						:disabled="postLoading"
						:loading="postLoading"
						@click="submit"
						class="submit_btn">
						提 交
					</button>
				</view>
			</u--form>
		</view>

		<!--    <view class="codeSetting">
      <view class="title">判定结果</view>
      <view class="rodio">
        <u-radio-group v-model="formData.status">
          <u-radio
            :customStyle="{ marginRight: '30px' }"
            :labelSize="14"
            shape="square"
            v-for="(item, index) in useDictionaryStore().filterDictList(
              'csmstatus'
            )"
            :key="index"
            :label="item.label"
            :name="item.value"></u-radio>
        </u-radio-group>
      </view>
    </view>
    <view class="judgmentDescription">
      <view class="judgmentDescriptionTitle">判定描述</view>
      <view class="judgmentDescriptionText">
        <u-textarea
          v-model="formData.remarks"
          placeholder="请输入内容"
          count></u-textarea>
      </view>
    </view>
    <view class="buttonAll">
      <view>
        <u-button
          class="button"
          type="primary"
          :disabled="postLoading"
          :loading="postLoading"
          @click="submit"
          text="提交"></u-button>
      </view>
      <view>
        <u-button class="button" @click="rest" text="重置"></u-button>
      </view>
    </view> -->
	</view>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import { http } from "@/utils/http";
import { useDictionaryStore } from "@/stores/useDictionaryStore";
const props = defineProps({
	result: {
		type: String,
		default: "",
	},
});
// 传过来的设备数据
let formData = reactive({
	id: "",
	status: "",
	equipCode: "",
	remarks: "",
});

// 初始化页面，获取检查详情
let taskInfo = ref<any>({});
const loading = ref(false);
// 判断是否已经填写
const isSelect = ref(false);
const result = ref({});
if (props.result) {
	result.value = JSON.parse(props.result);
	Object.assign(formData, result.value);
	if (formData.status == "") {
		isSelect.value = false;
	} else {
		isSelect.value = true;
	}
}
// 表单规则定义
const rules = ref({
	status: {
		type: "string",
		required: true,
		message: "请选择维护内容",
		trigger: ["change"],
	},
	time: {
		type: "string",
		required: true,
		message: "请选择时间",
		trigger: ["change"],
	},
});

// form信息重置
function resetData() {
	formData.status = "";
	formData.id = "";
	formData.equipCode = "";
	formData.remarks = "";
	uni.pageScrollTo({
		scrollTop: 0,
		duration: 100,
	});
}

// 提交
const postLoading = ref(false);
const ids = ref([]);
const submit = async () => {
	if (formData.status == "") {
		uni.showToast({
			title: "请选择一个判定项",
			icon: "none",
		});
		return;
	}
	postLoading.value = true;
	ids.value = [];
	ids.value.push(formData.id);
	console.log(ids.value);
	await http({
		method: "POST",
		url: `/eam/csmmaterialdata/updateMaterialList`,

		data: {
			ids: ids.value,
			status: formData.status,
			remarks: formData.remarks,
		},
	})
		.then((res) => {
			if (res) {
				uni.showToast({
					title: "提交成功",
				});
				setTimeout(() => {
					postLoading.value = false;
					resetData();
					uni.navigateTo({
						url: `/pages/eam/consumables/abnormalDisassembly/index?id='0'`,
						animationDuration: 0,
					});
				}, 1000);
			}
		})
		.finally(() => {
			postLoading.value = false;
		});
};
</script>

<style lang="scss" scoped>
// .baseForm {
//   // background-color: #fbfbff;
//   display: block;
//   min-height: 100vh;
//   padding: $uni-page-padding;
//   font-size: 14px;
//   .code {
//     display: flex;
//     justify-remarks: space-between;
//     margin-top: 20px;
//     width: 100%;
//     .codeTitle {
//       font-weight: 700;
//     }
//   }
//   .codeSetting {
//     display: flex;

//     width: 100%;
//     margin-top: 20px;
//     .title {
//       width: 170px;
//       font-weight: 700;
//     }
//     .rodio {
//       margin-left: 10px;
//     }
//   }
//   .judgmentDescription {
//     display: flex;
//     margin-top: 10px;
//     .judgmentDescriptionTitle {
//       width: 100px;
//       font-weight: 700;
//     }
//     .judgmentDescriptionText {
//       width: 400px;
//     }
//   }
//   .buttonAll {
//     display: flex;
//     margin-top: 20px;
//     width: 100%;
//     justify-remarks: flex-end;
//     .button {
//       margin-left: 20px;
//       width: 60px;
//       height: 35px;
//     }
//   }
// }
.handle-ok {
	min-width: 75px;
	color: #19be6b;
}
.card {
	background-color: #fff;
	margin: 10px 10px;
	border-radius: 8px;
	padding: 0 12px;
	transition: all 300ms ease;
	box-shadow: 0 2px 6px rgba(3, 121, 255, 0.05);
}

.overhidden {
	overflow: hidden;
}

.uni-table-th {
	font-size: 14px;
	font-weight: 400;
	color: #16254e;
}

uni-page-body {
	min-height: 100vh;
	height: 100%;
	background-color: #fbfbff;
}

.u-divider {
	margin: 10px 0;
}

.baseForm {
	background-color: #fbfbff;
	display: block;
	min-height: 100vh;
}

.title {
	font-size: 16px;
	margin: 6px 0 14px;
	font-weight: bold;
	.u-icon {
		margin-right: 3px;
	}
}

.submit_btn {
	margin: 0px 20rpx 20rpx 10rpx;
}
.grey_btn {
	margin: 0px 10rpx 20rpx 20rpx;
	height: 45px;
	line-height: 45px;
}
.submit_btn_div {
	position: fixed;
	display: flex;
	align-items: center;
	width: 100%;
	bottom: 0;
	z-index: 10;
	uni-button {
		flex: 1;
		border-radius: 10px;
	}
}

:deep(.u-form-item__body) {
	padding: 4px 0 12px;
}
:deep(.u-form-item) {
	.u-form-item__body__left__remarks__label {
		color: #a8b2bb;
		font-size: 14px;
		margin-bottom: 1px;
	}
	.u-form-item__body__left__remarks__required {
		font-size: 16px;
	}
	// 单选不可编辑样式
	.u-radio {
		.u-radio__icon-wrap--disabled {
			background-color: rgb(255, 255, 255) !important;
		}
		.u-radio__icon-wrap--disabled--checked {
			background-color: rgb(41, 121, 255) !important;
			border-color: rgb(41, 121, 255) !important;
			.u-icon__icon {
				color: #fff !important;
			}
		}
		.u-radio__text {
			color: #16254e !important;
			font-size: 14px !important;
		}
	}

	.u-textarea--disabled {
		background-color: #fff !important;
	}
	.uni-textarea-textarea {
		color: #16254e !important;
	}

	.input-box {
		width: 100%;
		border: 0.5px solid #dadbde !important;
		border-radius: 4px;
		.u-input {
			pointer-events: none;
			height: 34px;
			padding-left: 10px !important;
		}
		image {
			padding: 7px 6px;
			width: 20px;
			height: 20px;
		}
	}
}

.mt-10- {
	margin-top: -30px;
}

.unitable {
	width: calc(100% - 20px);
	margin: 0 10px 70px;
	box-shadow: 0 1px 8px 0px rgb(19 10 236 / 8%);
	border-radius: 4px;
}
</style>
